<?php

/**
* <class description>
* 
* @author
* @link
*/

class Contact extends Controller
{
    public function __construct()
    {
        parent::Controller();      
        $this->load->helper('form'); 
        $this->load->library("form_validation");    

    }    

    public function request_callback()
    {
        if($this->input->post("callback_submit") !== FALSE){

            if(validate_token("callback",$this->input->post("token",TRUE))){

                if($this->_validate_callback_form()){

                    $this->load->helper('send_email');     

                    $template_file = EMAIL_TEMPLATES_FOLDER.'callback'.INSTANCE_FILE_SUFFIX.'.html';
                    $template_data = array(
                            "NAME" => $this->input->post("callback_name",TRUE),
                            "NUMBER" => $this->input->post("callback_telephone",TRUE),
                            "TIMESTAMP" => date('l jS \of F Y \a\t h:i:s A')
                            );

                    send_email(EMAIL_SENDER, 
                                EMAIL_SENDER_NAME, 
                                CALLBACK_RECIPIENT, 
                                $this->lang->line('Callback_email_subject'), 
                                $template_file,
                                $template_data);

                    $this->load->view("request_callback_success");
                    return;

                }
            } 
        }

        $token = generate_token("callback",10);
        $this->load->view("request_callback_form",array("token" => $token));

    }

    private function _validate_callback_form(){
        
        $config = array(
                        array(
                         'field'   => 'callback_name',
                         'label'   => 'Name',
                         'rules'   => 'trim|required|xss_clean'
                        ),
                        array(
                         'field'   => 'callback_telephone',
                         'label'   => 'Telephone Number',
                         'rules'   => 'trim|required|xss_clean'
                        )  
                    );
        
        $this->form_validation->set_rules($config);       
        $this->form_validation->set_error_delimiters('<p class="error">', '</p>');
        
        if ($this->form_validation->run($this) == FALSE){
            return FALSE;
        }else
            return TRUE;

    }

}

/* End of file users.php */
/* Location: ./system/application/modules/frontoffice/controllers/home.php  */ 